package com.chinaunicom.factory;

import org.springframework.beans.factory.FactoryBean;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2021/11/24 14:18
 * Description: 自定义 FactoryBean, FactoryBean<T> 也是一个bean
 */
public class CarFactoryBean implements FactoryBean<Car> {
	private String carInfo;

	@Override
	public Car getObject() throws Exception {
		// 创建bean
		Car car = new Car();

		String[] split = carInfo.split(",");
		car.setMaxSpeed(Integer.valueOf(split[0]));
		car.setBrand(split[1]);
		car.setPrice(Double.valueOf(split[2]));

		return car;
	}

	@Override
	public Class<?> getObjectType() {
		return Car.class;
	}

	@Override
	public boolean isSingleton() {
		return FactoryBean.super.isSingleton();
	}

	public String getCarInfo(){
		return this.carInfo;
	}


	// 通过 逗号 分割符设置属性
	public void setCarInfo(String carInfo){
		this.carInfo = carInfo;
	}
}
